package com.bookcode.controller;

import com.bookcode.dao.PersonRepository;

import com.bookcode.entity.Person;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
public class PersonController {
    @Autowired
    private PersonRepository personRepository;
    @RequestMapping("/save")
    public String  save() {
        Person person = new Person("Li","wl");
        personRepository.save(person);
        return "Save OK!";    }
    @RequestMapping("/q1")
    public Person q1(String firstname) {
        Person person = personRepository.findByFirstName(firstname);
        return personRepository.save(person);    }
    @RequestMapping("/q2")
    public String q2(String lastname) {
        List<Person> listperson = personRepository.findByLastName(lastname);
        String persons ="  ";
        for(Person person:listperson) {persons += person + "      ";};
        return persons;           }
}
